OL_BLANK_IMG = 'geoext/lib/OpenLayers-2.11-rc1/img/blank.gif';
OpenLayers.DOTS_PER_INCH = 90.71428571428572;
OpenLayers.Util.onImageLoadError = function() {
            /**
             * For images that don't exist in the cache, you can display
             * a default image - one that looks like water for example.
             * To show nothing at all, leave the following lines commented out.
             */

            this.src = OL_BLANK_IMG;
            this.style.display = "";
};

function getLayers(){
	//add bing maps
	
    var apiKey = "AqTGBsziZHIJYYxgivLBf0hVdrAk9mWO5cQcb8Yux8sW5M8c8opEC2lZqKR1ZZXf";
    
    //add OSM
    osmlayer = new OpenLayers.Layer.OSM("Simple OSM Map");
    osmlayer = new OpenLayers.Layer.OSM("Simple OSM Map", "/osm/${z}/${x}/${y}.png");
    
	var road = new OpenLayers.Layer.Bing({
        key: apiKey,
        type: "Road",
        // custom metadata parameter to request the new map style - only useful
        // before May 1st, 2011
        metadataParams: {
            mapVersion: "v1"
        }
    });
    var aerial = new OpenLayers.Layer.Bing({
        key: apiKey,
        type: "Aerial"
    });
    var hybrid = new OpenLayers.Layer.Bing({
        key: apiKey,
        type: "AerialWithLabels",
        name: "Bing Aerial With Labels"
    });
    
    
    
    //add gwc
    var gwc_layer = new OpenLayers.Layer.GeoWebCache("TileCache Layer", "/gwc/ZGF0YS90aWxlcy5zcWxpdGU=/", //this is where the tiles are
    {
        type: 'png',
        isBaseLayer: false,
        prefix: 'EPSG_900913'//this is special, it has to be provided to match the folder naming convention
    });
    return [osmlayer, road, aerial, hybrid, gwc_layer];
}


function getControls(){
   return [new OpenLayers.Control.PanZoom({position: new OpenLayers.Pixel(2, 15)}),
	new OpenLayers.Control.Navigation(),
    new OpenLayers.Control.MousePosition(),
	new OpenLayers.Control.LayerSwitcher()];
}

function getMap(){
    //this can be get from the gwc seeding page, the preview map. anyway it is fixed for OSM/GOOGLE/MS
    var resolutions = [156543.03390625, 78271.516953125, 39135.7584765625, 19567.87923828125, 9783.939619140625, 4891.9698095703125, 2445.9849047851562, 1222.9924523925781, 611.4962261962891, 305.74811309814453, 152.87405654907226, 76.43702827453613, 38.218514137268066, 19.109257068634033, 9.554628534317017, 4.777314267158508, 2.388657133579254, 1.194328566789627, 0.5971642833948135, 0.29858214169740677, 0.14929107084870338, 0.07464553542435169, 0.037322767712175846, 0.018661383856087923, 0.009330691928043961, 0.004665345964021981];
    var mapOptions = {
        resolutions: resolutions,
        projection: new OpenLayers.Projection('EPSG:900913'),
        maxExtent: new OpenLayers.Bounds(-2.003750834E7, -2.003750834E7, 2.003750834E7, 2.003750834E7),
        //maxExtent: new OpenLayers.Bounds(-9236957.386267668,4858533.863157441,-9233729.12103511,4859550.377303473),
        units: "meters",
        controls: [],
        transitionEffect: 'resize'
    };
    var map = new OpenLayers.Map('map', mapOptions);
    
    
    //map.addLayer(demolayer);
    //map.setCenter(new OpenLayers.LonLat(-9236957.386267668,4858533.863157441), 5);
    //zoom to the layer
	map.addLayers(getLayers());
    
	return map;
}


